<?php

namespace Addons\Card\Controller;

use Addons\Card\Controller\BaseController;

class CardController extends BaseController {
	function config() {
		$this->getModel ();
		
		if (IS_POST) {
			if ($_POST ['config'] ['background'] == 11) {
				$_POST ['config'] ['background_custom'] = get_cover_url ( $_POST ['config'] ['bg'] );
			}
			$flag = D ( 'Common/AddonConfig' )->set ( _ADDONS, I ( 'config' ) );
			
			if ($flag !== false) {
				$this->success ( '保存成功', Cookie ( '__forward__' ) );
			} else {
				$this->error ( '保存失败' );
			}
		}
		
		$map ['name'] = _ADDONS;
		$addon = M ( 'Addons' )->where ( $map )->find ();
		if (! $addon)
			$this->error ( '插件未安装' );
		
		$addon_class = get_addon_class ( $addon ['name'] );
		
		$data = new $addon_class ();
		$addon ['addon_path'] = $data->addon_path;
		$addon ['custom_config'] = $data->custom_config;
		$db_config = D ( 'Common/AddonConfig' )->get ( _ADDONS );
		$addon ['config'] = include $data->config_file;
		if ($db_config) {
			foreach ( $addon ['config'] as $key => $value ) {
				if ($value ['type'] != 'group') {
					! isset ( $db_config [$key] ) || $addon ['config'] [$key] ['value'] = $db_config [$key];
				} else {
					foreach ( $value ['options'] as $gourp => $options ) {
						foreach ( $options ['options'] as $gkey => $value ) {
							! isset ( $db_config [$key] ) || $addon ['config'] [$key] ['options'] [$gourp] ['options'] [$gkey] ['value'] = $db_config [$gkey];
						}
					}
				}
			}
		}
		$this->assign ( 'data', $addon );
		
		$this->display ();
	}
	function show() {
		$tpl = 'show';
		$map ['uid'] = $this->mid;
		$info = M ( 'card_member' )->where ( $map )->find ();
		// dump($info);
		// dump(M ( 'card_member' )->getLastSql());
		if ($info) {
			$tpl = 'show_card';
            $this->getcoinscore($info);
		}
		
		$this->display ( $tpl );
	}
	// 使用介绍
	function introduction() {
		$this->display ();
	}
	// 适用门店
	function storeList() {

		$this->display ();
	}
    // 获取分公司列表
    function getFilialelist() {
        $res = M('com_jc')->field('com_jc,com_jc_name')->select();
        $this->ajaxReturn($res);
    }
    // 获取区域列表
    function getArealist() {
        $res = M('com_area')->field('com_area_code, com_area_name')->select();
        $this->ajaxReturn($res);
    }
    // 获取分公司对应门店列表
    function getStorelist() {
        $map['com_area_code'] = I('areaid');
        $res = M('com_md')->field('com_zip_name, com_md_add, com_md_tel, com_md_long, com_md_lat, com_md_type01')->where($map)->select();
        $this->ajaxReturn($res);
    }
	// 填写会员卡资料
	function writeCardInfo() {
		$map ['uid'] = $this->mid;
        $info = M('card_member')->where( $map )->find();
        $map2 ['cli_card'] = $info['number'];
		$info2 = M ( 'client_card' )->field('cli_name, cli_tel, cli_birthday, cli_add, cli_id, com_md_code, com_area_code')->where ( $map2 )->find ();
        $info2['cli_birthday'] = substr($info2['cli_birthday'],0, 10);

        $flist = M ( 'com_area' )->field('com_area_code as code, com_area_name as name')->select();
        $mdmap['com_area_code'] = $info2['com_area_code'];
        $mlist = M ( 'com_md' )->field('com_md_code as code, com_zip_name as name')->where($mdmap)->select();
		
		if (IS_POST) {
			$data ['cli_name'] = I ( 'cli_name' );
			$data ['cli_tel'] = I ( 'cli_tel' );
            $data ['cli_birthday'] = I ( 'cli_birthday' );
            $data ['cli_add'] = I ( 'cli_add' );
            $data ['cli_id'] = I ( 'cli_id' );
            $data ['com_area_code'] = I( 'com_area_code' );
            $data ['com_md_code'] = I( 'com_md_code' );
			if ($info && !empty($data ['cli_name']) && !empty($data ['cli_tel'])) {
				$res = M ( 'client_card' )->where ( $map2 )->save ( $data );
                $data ['cli_card'] = $map2 ['cli_card'];
                $res2 = M ( 'client_card_log' )->add ( $data );

                /*移动用户到分组*/
                if($data['com_area_code']){
                    $this->groupsmebers($data['com_area_code']);
                }
			}
			redirect ( addons_url ( 'Card://Card/showCard' ) );
		}


        $this->assign ( 'flist', $flist );
        $this->assign ( 'mlist', $mlist );
		$this->assign ( 'info', $info2 );
		$this->display ( 'write_cardinfo' );
	}

    //根据区域获取门店列表
    function getmdList(){
        $map['com_area_code'] = I('areacode');
        $res = M('com_md')->field('com_md_code as code, com_zip_name as name')->where($map)->select();
        $this->ajaxReturn($res);
    }

    //申请新会员
    function applyVip() {
        $this->display ( 'applyvip' );
    }

	function index() {
		$this->display ();
	}
	// 绑定实体会员卡
	function bindCard() {
        $this->assign ( 'info', I('openid') );
        $this->display ( 'bind_card' );
	}
	// 兑换
	function exchange() {
		$this->display ();
	}
    // 微币积分互换
    function wbexchange() {
        $map ['uid'] = $this->mid;
        $map2['name'] = 'wbexchange';
        $map3['name'] = 'ecexam';
        $info = M ( 'card_member' )->where ( $map )->find ();
        $rate = M('credit_config')->where($map2)->getField('score');
        $ecexam = M('credit_config')->where($map3)->getField('score');
        $this->getcoinscore($info);
        $this->assign('rate', $rate);
        $this->assign('ecexam', $ecexam);
        $this->display ();
    }
    // 微币积分兑换逻辑
    function wbtoexchange(){
        $exchangetype = I('exchangetype');
        $num = I('fnum');
        if($exchangetype == 'wtc'){
            $exam = M('credit_config')->where(array('name'=>'ecexam'))->getField('score');
            if($num < $exam){
                $data['statu'] = 0;
                $data['content'] = '微币数未达到门限!';
                $this->ajaxReturn($data);
                return;
            }
        }
        $map['uid'] = $this->mid;
        $map2['name'] = 'wbexchange';
        $rate = M('credit_config')->where($map2)->getField('score');

        $result = M ( 'client_card' )->join('__CARD_MEMBER__ ON __CLIENT_CARD__.cli_card = __CARD_MEMBER__.number')->where ( $map )->find();
        $jf = $result['cli_card_jf'];
        $wb = M('follow')->where(array('id'=>$this->mid))->getField('score');
        switch($exchangetype){
            case 'ctw':
                if($jf < $num){
                    $jfmap['cli_card_jf'] = 0;
                    $wbmap['score'] = $wb + $jf*$rate;

                    $logdata['score'] = $jf*$rate;
                }
                else{
                    $jfmap['cli_card_jf'] = $jf-$num;
                    $wbmap['score'] = $wb + $num*$rate;

                    $logdata['score'] = $num*$rate;
                }
                break;
            case 'wtc':
                if($wb < $num){
                    $wbmap['score'] = 0;
                    $jfmap['cli_card_jf'] = $jf + $wb/$rate;

                    $logdata['score'] = 0 - $wb;
                }
                else{
                    $wbmap['score'] = $wb - $num;
                    $jfmap['cli_card_jf'] = $jf + $num/$rate;

                    $logdata['score'] = 0 - $num;
                }
                break;
        };
        $jfres = M ( 'client_card' )->where ( array('cli_card'=>$result['cli_card']) )->save($jfmap);
        $wbres = M('follow')->where(array('id'=>$this->mid))->save($wbmap);
        $data = array('score'=>$jfmap['cli_card_jf'], 'wb'=>$wbmap['score']);
        if($jfres && $wbres){
            $logdata['uid'] = $this->mid;
            $logdata['credit_name'] = 'wbexchange';
            $logdata['cTime'] = time();
            $logdata['token'] = get_token();
            $logdata['remark'] = $rate;
            M('credit_data')->add($logdata);

            $data['statu'] = 1;
            $data['content'] = '兑换成功!';
            $this->ajaxReturn($data);
        }
        else{
            $data['statu'] = 0;
            $data['content'] = '兑换失败!';
            $this->ajaxReturn($data);
        }
    }
	// 优惠券
	function ticket() {
		$this->display ();
	}
    //获取微币和积分
    function getcoinscore($info){
        $this->checkedCredit();
        //获取总微币
        $map['id'] = $this->mid;
        $map['token'] = get_token();
        $coin = M ( 'follow' )->where ( $map )->getField('score');
        !empty($coin) || $coin = 0;
        //获取总积分
        $map2['cli_card'] = get_card_number();
        $score = M ('client_card')->where($map2)->getField('floor(cli_card_jf)');
        !empty($score) || $score = 0;

        $this->assign('score', $score);
        $this->assign('coin', $coin);
        $this->assign ( 'info', $info );
    }

	// 领取后
	function showCard() {
		$map ['uid'] = $this->mid;
        $map ['token'] = get_token();
		$info = M ( 'card_member' )->where ( $map )->find ();
        if($info){
            $this->getcoinscore($info);
            $this->assign ( 'uid', $this->mid );

            $this->display ( 'show_card' );
        }
        else{
            redirect ( addons_url ( 'Card://Card/show' ) );
        }
	}

    function checkedCredit(){
        //获取签到标识
        $creditInfo = D('Common/Credit')->getLastCreditLog('member_checkin');
        if ($creditInfo) {
            //判断是否今天
            $cTime = intval($creditInfo['cTime']);
            if (date('Y-m-d') === date('Y-m-d', $cTime)) {
                $hasCheckin = true;
            } else {
                $hasCheckin = false;
            }
        } else {
            $hasCheckin = $creditInfo !== false;
        }
        $this->assign ( 'hascheckin', $hasCheckin );
        if(IS_POST){
            $this->ajaxReturn($hasCheckin);
        }
    }

    //发送验证码
    function sendPhoneCode(){
        if(session('?vcode') && time()-session('vcodetime') < 300){
        }
        else{
            session('vcode', randCode(4,1));
        }

        session('vcodetime', time());
        if(session('?vcodenum') && session('vcodenum')>=5){
            $res = "发送验证码超出上限";
            session('vcodenum',null);
        }
        else{
            if(session('?vcodenum')){
                session('vcodenum', session('vcodenum') + 1);
            }
            else{
                session('vcodenum', 1);
            }
            $phone = I('phone');
            $content = '此验证码只用于申请绑定国药会员卡，验证码提供给他人将导致会员卡被盗。' . session('vcode') . '(国药验证码)。请勿转发';
            $url = 'http://api.cnsms.cn/?ac=send&encode=utf8&' .
                'uid=100159&' .
                'pwd=4f0173a68ce185765cbe33359520aed6&' .
                'mobile=' . $phone . '&' .
                'content=' . $content;
            $res = JsonGet($url);
            if($res == 100){
                $data['uid'] = get_mid();
                $data['sendtime'] = time();
                M('sendmsg_log')->add($data);
            }
        }
        $this->ajaxReturn($res);
//        $this->ajaxReturn(session('vcode'));
    }

    //验证用户短信
    function checkPhoneCode(){
        $vcode = I('vcode');
        $res = array("data"=>"验证成功", "statu"=>0);
        if(time()-session('vcodetime') < 300){
            if($vcode == session('vcode')){
                session('vcode',null);
                session('vcodetime',null);
                $res['data'] = "验证成功";

                /*记录发送验证码到提交的时间日志*/
                $map['uid'] = get_mid();
                $logres = M('sendmsg_log')->where($map)->order('id desc')->find();
                if(empty($logres['checkedtime'])){
                    $map['id'] = $logres['id'];
                    M('sendmsg_log')->where($map)->save(array('checkedtime'=>time()));
                }
            }
            else{
                $res['data'] = "验证码输入错误";
                $res['statu'] = 1;
            }
        }
        else{
            $res['data'] = "验证码已过期";
            $res['statu'] = 1;
            session('vcodetime',null);
            session('vcode',null);
        }
        return $res;
    }

    //移动用户到分组
    function groupsmebers($id){
        if(!$id){
            $id = 0;
        }
        $token = get_token();
        $access_token = get_access_token ( $token );
        if (empty ( $access_token )) {
            return false;
        }
        $url = "https://api.weixin.qq.com/cgi-bin/groups/members/update?access_token=" . $access_token;
        $postdata['openid'] = get_openid();
        $postdata['to_groupid'] = $id;
        $res = JsonPost($url, json_encode($postdata));
        return json_decode($res) ;
    }

    function getgroups(){
        $token = get_token();
        $access_token = get_access_token ( $token );
        $url = "https://api.weixin.qq.com/cgi-bin/groups/get?access_token=" . $access_token;
        $res = JsonGet($url);
        $this->ajaxReturn($access_token) ;
    }

    //绑定会员卡
    function BindOneCard(){
        $map['number'] = I('cardid');
        $data ['cTime'] = time ();
        $data ['token'] = get_token ();
        $data ['uid'] = $map2 ['id'] = $this->mid;
        $data ['number'] = $map['number'];
        $res =  M ( 'card_member' )->where($map)->find();
        if(!$res && $data ['uid']>0){
            M ( 'card_member' )->add ( $data );
            M ( 'follow' )->where ( $map2 )->setField ( 'status', 2 );
            // 增加微币
            $credit = add_credit ( 'card_bind' );

            /*移动用户到分组*/
            $numres = M ( 'client_card' )->where ( $map )->getField('com_area_code');
            $this->groupsmebers($numres['com_area_code']);

            $this->ajaxReturn('绑定成功! 微币+' . $credit);
        }
        else{
            $this->ajaxReturn('绑定失败，该微信已绑定会员卡!');
        }
    }

    //绑定会员
    function checkBind(){
        $phone = I('phone');
        $data ['uid'] = $map2 ['id'] = $this->mid;
        $data ['cTime'] = time ();
        $data ['token'] = get_token ();
        $phonemap['cli_tel'] = $phone;
        $chres = $this->checkPhoneCode();
        if($chres['statu'] == 0){
            $numres = M ( 'client_card' )->field('cli_card, cli_card_jf, com_area_code')->where ( $phonemap )->select();
            switch(count($numres)){
                case 0:
                    $chres['data'] = "该手机号未申请";
                    $chres['statu'] = 1;
                    break;
                case 1:
                    $chres['data'] ="绑定成功";
                    $data ['number'] = $numres[0]['cli_card'];
                    break;
                default:
                    $chres['data'] =$numres;
                    $chres['statu'] = 2;
                    break;
            }

            $res =  M ( 'card_member' )->where($data)->find();
            $credit = 0;
            if(!$res && $chres['statu'] == 0 && $data ['uid'] >0){
                M ( 'card_member' )->add ( $data );
                M ( 'follow' )->where ( $map2 )->setField ( 'status', 2 );
                // 增加微币
                $credit = add_credit ( 'card_bind' );

                /*移动用户到分组*/
                $this->groupsmebers($numres[0]['com_area_code']);
            }
            if($chres['statu'] != 2){
                $chres['data'] = $chres['data'] . ', 微币+' . $credit;
            }
            $this->ajaxReturn($chres);
        }
        else{
            $this->ajaxReturn($chres);
        }
    }

    //申请新会员
    function checkApply(){
        $data ['uid'] = $map2 ['id'] = $this->mid;
        $data ['cTime'] = time ();
        $data ['token'] = get_token ();
        $data2 ['cli_name'] = I ( 'cli_name' );
        $data2 ['cli_tel'] = I ( 'cli_tel' );

        $phonemap['cli_tel'] = I('cli_tel');
        $chres = $this->checkPhoneCode();

        if($chres['statu'] == 0){
            $numres = M ( 'client_card' )->where ( $phonemap )->select();
            switch(count($numres)){
                case 0:
                    $config = getAddonConfig ( 'Card' );
                    $map_token ['token'] = get_token ();
                    $data ['number'] = M ( 'client_card' )->getField ( "max(cli_card) as cli_card" );
                    if (empty ( $data ['number'] ) || $data ['number']<$config ['length']) {
                        $data ['number'] = $config ['length'];
                    } else {
                        $data ['number'] += 1;
                        $data ['number'] = str_replace(4, 5, $data ['number']);
                    }
                    // 增加微币
                    $credit = add_credit ( 'card_bind' );

                    //国药会员表和日志表新增
                    $data2 ['cli_card'] = $data ['number'];
                    M ( 'client_card' )->add ( $data2 );
                    $chres['data'] = "申请成功, 微币+" . $credit;
                    break;
                case 1:
                    $chres['data'] ="号码已绑定会员卡号";
                    M ( 'client_card' )->where ( $phonemap )->setField('cli_name', I('cli_name'));
                    $data2 ['cli_card'] = $numres[0]['cli_card'];
                    $data ['number'] = $data2 ['cli_card'];
                    break;
                default:
                    $chres['data'] ="号码绑定多个会员";
                    M ( 'client_card' )->where ( array("cli_card"=>$numres[0]['cli_card']) )->setField('cli_name', I('cli_name'));
                    $data2 ['cli_card'] = $numres[0]['cli_card'];
                    $data ['number'] = $data2 ['cli_card'];

                    $chres['data'] =$numres;
                    $chres['statu'] = 2;
                    break;
            }
            if($chres['statu'] == 0){
                M ( 'card_member' )->add ( $data );
                M ( 'client_card_log' )->add ( $data2 );
                M ( 'follow' )->where ( $map2 )->setField ( 'status', 2 );
            }
            $this->ajaxReturn($chres);
//                redirect ( addons_url ( 'Card://Card/showCard' ) );
        }
        else{
            $this->ajaxReturn($chres);
        }
    }

    //测试
//    function test(){
//        $map ['uid'] = $this->mid;
//        $info = M('card_member')->where( $map )->find();
//        $map2 ['cli_card'] = $info['number'];
//        $info2 = M ( 'client_card' )->field('cli_name, cli_tel, com_area_code, cli_birthday, cli_add, cli_id')->where ( $map2 )->find ();
//        $flist = M ( 'com_jc' )->field('com_jc as jc, com_jc_name as name')->select();
//
//        $this->ajaxReturn($info2);
//    }

    /*消费记录*/
    function costRecord(){
        $map['uid'] = $this->mid;
        $res = M('card_member')->where($map)->find();
        if(!$res){
            redirect ( addons_url ( 'Card://Card/show' ) );
        }
        else{
            //获取总积分
            $map2['cli_card'] = get_card_number();
            $score = M ('client_card')->where($map2)->getField('floor(cli_card_jf)');
            !empty($score) || $score = 0;
            $this->assign('score', $score);
//            $this->ajaxReturn($score);
            $this->display('costrecord');
        }
    }

    /*消费记录加载*/
    function loadcostRecord(){
        $page = I('page');
        $cmap['uid'] = $this->mid;
        $cmap['token'] = get_token();
        $card = M('card_member')->where($cmap)->find();
        $map['cli_card'] = $card['number'];
        $res = M('cli_card_jf')->table('wp_cli_card_jf jf')
            ->join('wp_com_md md on md.com_md_code = jf.com_md_code')
            ->field('jf.com_md_code as mdcode, jf.com_db_id as dbid, com_zip_name, cli_card_jf_list_no as listid, cli_card, cli_card_jf_type as jf_type, floor(sum(cli_card_jf_num)) as jf_num, cli_card_jf_date_up as date')
            ->where($map)
            ->order('date desc')
            ->group('listid,mdcode,dbid')
            ->limit($page*10, ($page+1)*10)
            ->select();
        for($i=0; $i<count($res); $i++){
            $statu_fw = M('credit_comment')->where(array('listid'=>$res[$i]['listid'],'uid'=>$cmap['uid']))->find();
            if($statu_fw){
                $res[$i]['statu_fw'] = true;
            }
            else{
                $res[$i]['statu_fw'] = false;
            }
            $statu_yx = M('comment_listno')->where(array('listid'=>$res[$i]['listid'],'uid'=>$cmap['uid']))->find();
            if($statu_yx){
                $res[$i]['statu_yx'] = true;
            }
            else{
                $res[$i]['statu_yx'] = false;
            }
        }
        $this->ajaxReturn($res);
    }

    /*微信解除会员卡绑定*/
    function unBind(){
        $map['uid'] = $this->mid;
        $map['token'] = get_token();
        $res = M('card_member')->where($map)->delete();
        if($res >= 1){
            $credit = add_credit('uncardbind');
            $this->ajaxReturn(array('statu'=>1, 'content'=>'解绑成功, 积分' . $credit));
        }
        else{
            $this->ajaxReturn(array('statu'=>0, 'content'=>'您未绑定'));
        }
    }

    /*下载积分表*/
//    function jflogdown(){
//        $result = M('cli_card_jf')->field('com_md_code,cli_card_jf_list_no,cli_card,cli_card_jf_type,cur_no')->select();
//        $str = "门店编码\t门店销售单号\t会员卡号\t积分类型\t门店操作员\r\n";
//        $str = iconv('utf-8','gb2312',$str);
//        foreach($result as $row){
//            $mdcode = $row['com_md_code']; //中文转码
//            $listid = iconv('utf-8','gb2312',$row['cli_card_jf_list_no']);
//            $card = iconv('utf-8','gb2312',$row['cli_card']);
//            $jftype = iconv('utf-8','gb2312',$row['cli_card_jf_type']);
//            $curid = iconv('utf-8','gb2312',$row['cur_no']);
//            $str .= $mdcode."\t".$listid."\t".$card."\t".$jftype."\t".$curid."\r\n"; //用引文逗号分开
//        }
//        $filename = 'jifen-' . date('Y-m-d').'.txt'; //设置文件名
//        $this->creat_csv($filename, $str); //导出
//    }
//    function export_csv($filename,$data) {
//        header("Content-type:text/csv");
//        header("Content-Disposition:attachment;filename=".$filename);
//        header('Cache-Control:must-revalidate,post-check=0,pre-check=0');
//        header('Expires:0');
//        header('Pragma:public');
//        echo $data;
//    }
//    function creat_csv($filename,$data){
//        header("Content-Type:text/html;charset=utf-8");
//        $path = 'd:/' . $filename;
//        if(file_exists($path)){
//            echo '文件已存在';
//        }
//        else{
//            $fp = fopen($path, "a"); //打开csv文件，如果不存在则创建
//            fwrite($fp,$data); //写入数据
//            fclose($fp); //关闭文件句柄
//            echo '成功';
//        }
//    }
//    function get_token(){
//        $this->ajaxReturn(get_token());
//    }
//
//    function getaccesstoken(){
//        $this->ajaxReturn(get_access_token(get_token()));
//    }
    /*会员类型统计*/
    function getvipgroupinfo(){
        $count = M('card_member')->field('count(number) as count')->find();

        $maplike['number'] = array('like','9%');
        $linecount = M('card_member')->field('count(number) as count')->where($maplike)->find();
        $unlinecount = $count['count'] - $linecount['count'];
        $this->ajaxReturn(array('allcount'=> intval($count['count'], 10), 'linecount'=>intval($linecount['count'], 10), 'unlinecount'=>$unlinecount));
    }
//    function geturl(){
//        $this->ajaxReturn(addons_url ( 'Card://Card/show'));
//    }

//    function getvipdetailinfo(){
//        $res1 = M('cli_card_jf')
//            ->field('cli_card_jf_list_no as listid, cli_card as cardid, sum(cli_card_jf_num) as sumjf')
//            ->where('cli_card_jf_type=1 and cli_card_jf_date > "2015-04-02 00:00:00" and cli_card_jf_date < "2015-04-09 00:00:00"')
//            ->group('cli_card_jf_list_no, com_md_code')
//            ->select();
//        $res2 = M('cli_card_jf')
//            ->table('wp_cli_card_jf jf')
//            ->join('wp_card_member member ON member.number = jf.cli_card')
//            ->field('jf.cli_card_jf_list_no as listid, jf.cli_card as cardid, sum(jf.cli_card_jf_num) as sumjf')
//            ->where('jf.cli_card_jf_type=1 and cli_card_jf_date > "2015-04-02 00:00:00" and cli_card_jf_date < "2015-04-09 00:00:00"')
//            ->group('jf.cli_card_jf_list_no, com_md_code')
//            ->select();
//        $res3 = M('cli_card_jf')
//            ->field('cli_card_jf_list_no as listid, cli_card as cardid, sum(cli_card_jf_num) as sumjf')
//            ->where('cli_card_jf_type=1 and cli_card_jf_date > "2015-04-02 00:00:00" and cli_card_jf_date < "2015-04-09 00:00:00"')
//            ->where(array('cli_card'=>array('like','9%')))
//            ->group('cli_card_jf_list_no, com_md_code')
//            ->select();
//        $alljf = 0;
//        $uandlinejf = 0;
//        $linejf = 0;
//        foreach($res1 as $all){
//            $alljf += $all['sumjf'];
//        }
//        foreach($res2 as $uandline){
//            $uandlinejf += $uandline['sumjf'];
//        }
//        foreach($res3 as $line){
//            $linejf += $line['sumjf'];
//        }
//        $this->ajaxReturn(array(
//            'allvip'=>array('xfcount'=>count($res1),'alljf'=>$alljf ),
//            'wxvip'=>array('xfcount'=>count($res2),'uandlinejf'=>$uandlinejf),
//            'linevip'=>array('xfcount'=>count($res3),'linejf'=>$linejf )
//        ));
//    }
//
//    /*统计会员卡数据*/
//    function getvipnumberinfo(){
//        $res1 = M('cli_card_jf')
//            ->field('cli_card as cardid')
//            ->where('cli_card_jf_type=1 and cli_card_jf_date > "2015-04-02 00:00:00" and cli_card_jf_date < "2015-04-09 00:00:00"')
//            ->group('cli_card')
//            ->select();
//        $res2 = M('cli_card_jf')
//            ->table('wp_cli_card_jf jf')
//            ->join('wp_card_member member ON member.number = jf.cli_card')
//            ->field('jf.cli_card as cardid')
//            ->where('jf.cli_card_jf_type=1 and cli_card_jf_date > "2015-04-02 00:00:00" and cli_card_jf_date < "2015-04-09 00:00:00"')
//            ->group('jf.cli_card')
//            ->select();
//        $res3 = M('cli_card_jf')
//            ->field('cli_card as cardid')
//            ->where('cli_card_jf_type=1 and cli_card_jf_date > "2015-04-02 00:00:00" and cli_card_jf_date < "2015-04-09 00:00:00"')
//            ->where(array('cli_card'=>array('like','9%')))
//            ->group('cli_card')
//            ->select();
//        $this->ajaxReturn(array(
//            'allvip'=>array('count'=>count($res1)),
//            'wxvip'=>array('count'=>count($res2)),
//            'linevip'=>array('count'=>count($res3))
//        ));
//    }
//
//    /*会员类型统计-时间限制*/
//    function gettimevipgroupinfo(){
//        $count = M('card_member')->field('count(number) as count')->where('ctime < 1428508800')->find();
//
//        $maplike['number'] = array('like','9%');
//        $linecount = M('card_member')->field('count(number) as count')->where($maplike)->find();
//        $unlinecount = $count['count'] - $linecount['count'];
//        $this->ajaxReturn(array('allcount'=> intval($count['count'], 10), 'linecount'=>intval($linecount['count'], 10), 'unlinecount'=>$unlinecount));
//    }
}
